const Mock = require('mockjs')
const { mock } = require('mockjs')

Mock.Random.extend({
  phone: function() {
    var phonePrefixs = ['132', '135', '189'] // 自己写前缀哈
    return this.pick(phonePrefixs) + Mock.mock(/\d{8}/) //Number()
  },
})

const List = []
const count = 999
for (let i = 0; i < count; i++) {
  List.push(
    mock({
      id: '@id',
      phone: '@phone',
      name: '@cname',
      email: '@email',
    })
  )
}

module.exports = [
  {
    url: '/dialog/getList',
    type: 'post',
    response(config) {
      const { page = 1, pageSize = 20 } = config.body.pageBean
      const { querys = [] } = config.body
      let filterList = List
      // 条件查询
      if (querys.length) {
        filterList = List.filter((item) => {
          let flag = false
          querys.forEach((subItem) => {
            if (
              item[subItem.property] &&
              item[subItem.property].indexOf(subItem.value) > -1
            ) {
              flag = true
            }
          })
          return flag
        })
      }
      const pageList = filterList.filter(
        (item, index) =>
          index < pageSize * page && index >= pageSize * (page - 1)
      )
      return {
        code: 200,
        msg: 'success',
        page: page,
        pageSize,
        totalCount: filterList.length,
        data: pageList,
      }
    },
  },
]
